package com.sts.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sts.bean.Base_eq;
import com.sts.bean.Eq_run;
import com.sts.service.IEq_runService;

/**
 * 设备运行时的controller
 * @author FENG
 *
 */

@Controller
public class Eq_runController {
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource
	private IEq_runService runSer ;
	
	@RequestMapping("/addEq_run")
	@ResponseBody
	public String addEq_run(String data){
		log.debug("addEq_run controller in");
		String result = "" ;
		log.debug("数据:" + data);
		//将JSON对象转换为对象
		Eq_run run = JSON.parseObject(data,Eq_run.class) ;
		log.debug(run.toString());
		boolean b = runSer.addEq_run(run) ;
		if(b){
			result = "success" ;
		}else {
			result = "false" ;
		}
		
		log.debug("addEq_run controller out");
		return result;
	}
	
	/**
	 * 对设备的运行数据信息进行查询
	 * @param eq_id
	 * @param car_id
	 * @return
	 */
	@RequestMapping(value="/selectAllLog",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String selectAllLog(String eq_id,String car_id,String page,String limit,String data1,String day){
		log.debug("selectAllLog  controller in");
		log.debug("page:" + page + ",eq_id:" + eq_id + ",car_id:" + car_id + ",limit:" +limit+ ",data1:" + data1+ ",day:" + day);
		List<Eq_run> list = new ArrayList<Eq_run>();
		list = runSer.selectEq_run(eq_id,car_id,page,limit,data1,day);
		log.debug("eq_id:" + eq_id + "  car_id:" + car_id ) ;
		int length = runSer.selectSize(eq_id,car_id,data1,day);
		String str = JSON.toJSONString(list);
		if(limit.equals("100")) {
			
		}else{
			str= "{\"code\":0,\"msg\":\"  \",\"count\":\""+length+"\",\"data\":"+str+"}";
			
		}
		log.debug("哈哈哈的啊d+++:" + str);
		
		log.debug("selectAllLog controller out");
		
		return str;
	}
	
	/**
	 * 对设备的实时温度进行查询
	 * @param eq_id
	 * @param car_id
	 * @return
	 */
	@RequestMapping(value="/selectTemp",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String selectTemp(){
		log.debug("selectTemp  controller in");
		List<Eq_run> list = new ArrayList<Eq_run>();
		list = runSer.selTemp();
		String str = JSON.toJSONString(list);
		log.debug("selectTemp  controller out");
		return str ;
	}
	
	
	
}
